<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/css/public.css" media="all">

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form id="userForm" class="layui-form" method="post" onsubmit="return false;">
<div class="layui-form layuimini-form" lay-filter="add_ncc">

    <div class="layui-form-item">
        <label class="layui-form-label required">中文名</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入用户名称" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
            <label class="layui-form-label required">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" lay-verify="required|email" lay-reqtext="邮箱不能为空" placeholder="请输入邮箱"  class="layui-input">
            </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">用户组</label>
        <div  id="members" name="members" class="layui-input-block"></div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text"  class="layui-input layui-disabled" value="生成重置密码连接，通过邮件发送给用户">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">角色</label>
        <div class="layui-input-block">
            <select name="is_superuser">
                <option value="0" selected="">用户</option>
                <option value="1">超级管理员</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">失效日期</label>
        <div class="layui-input-block">
            <input type="text" name="lnvalid_date" id="date" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">访问控制</label>
        <div class="layui-input-block">
            <input name="experm" type="radio" value="1" title="超级管理员">
            <input name="experm" type="radio" value="0" title="普通用户" checked>
        </div>
    </div>

    <div class="layui-form-item">
            <label class="layui-form-label required">手机</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="phone"  class="layui-input">
            </div>
    </div>

    <div class="layui-form-item">
            <label class="layui-form-label required">微信</label>
            <div class="layui-input-block">
                <input type="text" name="weixin" lay-verify="required"  class="layui-input">
            </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">备注</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入备注" class="layui-textarea" name="info" lay-verify="required"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label"></label>
       <button class="layui-btn" lay-filter="UserAdd" type="submit" lay-submit >立即提交</button>
    </div>




</div>
</form>

<script src="/static/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/layui/sm_select/xm-select.js"></script>
<script>
    layui.use(['form','laydate'],function () {
        window.form = layui.form
            ,window.$ = layui.$
            , laydate = layui.laydate;

        form.render();
        //日期
        laydate.render({
            elem: '#date'
        });

        //监听提交
        form.on('submit(UserAdd)', function (data) {
            //发异步，把数据提交给php
            var name = data.field.name;
            var username = data.field.username;
            var email = data.field.email;
            var members = data.field.members;
            var is_superuser = data.field.is_superuser;
            var phone = data.field.phone;
            var lnvalid_date = data.field.lnvalid_date;
            var experm = data.field.experm;

            var weixin = data.field.weixin;
            var info = data.field.info;

            //alert(JSON.stringify(data));

            $.ajax({
                type: 'post',
                url: "/users/user/create/",
                data: {name: name,username:username,
                       email: email,members:members,
                       is_superuser: is_superuser,phone:phone,
                       lnvalid_date: lnvalid_date,experm:experm,
                       weixin: weixin,info:info
                        },
                success: function (res) {
                    if (res.status == 0) {
                        layer.alert(res.msg, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                           //刷新页面
                            parent.location.reload();
                        });
                         //parent.layer.reload();

                    } else {
                        layer.alert(res.msg, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新页面
                            parent.location.reload();
                        });
                    }
                }
            });
            return false;
        });



    });


    var demo1 = xmSelect.render({
                el: '#members',
                name: 'members',
                filterable: true,
                radio: true,
                data: []
            })

    var test = {
        method1: function (data)
        {
            demo1.update({data:data});

        },
        method2: function () {
            return demo1.getValue();
        }

    }
    

</script>
</body>
</html>